import GoodInfoModal from '@/views/box/components/GoodInfoModal'
import RecommendLookDraw from '@/views/box/workbench/fashioner/module/RecommendLookDraw'
import { brandCondition } from '@/api/box/workbench'
export const lookMixin = {
  components: {
    GoodInfoModal,
    RecommendLookDraw
  },
  data () {
    return {
      unionId: '',
      qiyuCustomer: '',
      MobilePhone: '',
      storeId: '',
      weid: '',
      weBrandsList: [],
      weBrand: '',
      comebyname: [
        {
          weid: 2738574294,
          name: 'JNBY'
        },
        {
          weid: 2822095692,
          name: 'LESS'
        },
        {
          weid: 2504948039,
          name: 'CROQUIS'
        },
        {
          weid: 4,
          name: 'jnby by JNBY'
        },
        {
          weid: 6924108367,
          name: 'Pomme de terre'
        },
        {
          weid: 15,
          name: 'APN73'
        },
        {
          weid: 8348044436,
          name: 'JNBYHOME'
        },
        {
          weid: 11,
          name: 'Outlet'
        },
        {
          weid: 5,
          name: '江南布衣+'
        }
      ],
      fromprogramname: ''
    }
  },
  created () {
    this.getparameters()
  },
  mounted () {
  },
  methods: {
    async getparameters () {

      // this.$refs.recommendLookDraw.show()
      this.unionId = this.$route.query.UserId
      console.log(this.unionId)
      var qiyuCustomer = decodeURIComponent(this.$route.query.qiyuCustomer);
      console.log(qiyuCustomer)
      this.qiyuCustomer = JSON.parse(qiyuCustomer)
      this.MobilePhone = this.$route.query.MobilePhone
      this.storeId = String(this.qiyuCustomer.crm_storeId)
      this.weid = this.qiyuCustomer.crm_weid
      let comebyname = this.comebyname.filter(e => e.weid == this.weid)
      this.fromprogramname = comebyname[0].name
      await this.getBrands()
      let weB = this.weBrandsList.filter(e => e.weid == this.weid)
      if (weB.length > 0) {
        this.weBrand = weB[0].arcBrandId
      }
      console.log(this.weid, this.weBrand);
    },
    // 查看推荐LOOK
    showRecommend (item) {
      console.log(item)
      this.$refs.recommendLookDraw.show(item)
    },
    sendcard (img, title, id, price) {
      var data = {};
      if (!price) {
        data = {
          picture: img ? img : 'https://img.bzhz.jnbygroup.com/cloth.png',
          title: title,
          url: '/ec_goods/detail?id=' + id,  // 正式
          // url: '/pages/goods/detail?id=' + id, // 测试
          showCustomMsg: 1
        }
      } else {
        data = {
          picture: img ? img : 'https://img.bzhz.jnbygroup.com/cloth.png',
          title: title,
          price: price,
          url: '/ec_goods/detail?id=' + id,  // 正式
          // url: '/pages/goods/detail?id=' + id, // 测试
          showCustomMsg: 1
        }
      }
      console.log(data)
      window.parent.postMessage(data, '*');
    },
    getBrands () {
      return brandCondition().then(res => {
        if (res.code == 0) {
          this.weBrandsList = res.data
        }
      })
    }
  }
}
export const sendCardMixin = {
  methods: {
    sendOrderCard (item) {
      const {url, orderCode, orderStatus, goodsNumber, price, orderTime} = item
      let orderStatusText = ''
      switch(orderStatus)
      {
        case '0':
          orderStatusText='待付款'
          break;
        case '1':
          orderStatusText='待付款'
          break;
        case '2':
          orderStatusText='待发货'
          break;
        case '3':
          orderStatusText='待发货'
          break;
        case '4':
          orderStatusText='待收货'
          break;
        case '5':
          orderStatusText='待收货'
          break;
        case '7':
          orderStatusText='待评价'
          break;
        case '8':
          orderStatusText='已完成'
          break;
        case '9':
          orderStatusText='已取消'
          break;
      }
      const data = {
        picture: url ? url : 'https://img.bzhz.jnbygroup.com/cloth.png',
        title: '订单咨询',
        url: `/ec_orderDetail/detail?orderNo=${orderCode}`,
        showCustomMsg: 1,
        orderId: orderCode,
        cardType: 1,
        orderStatus: orderStatusText,
        orderTime: orderTime,
        payMoney: `实付￥${price}`,
        orderCount: `共${goodsNumber}件`
      }
      console.log(data, 'qiyudata**************')
      window.parent.postMessage(data, '*');
    },
    sendcard (img, title, id, price) {
      console.log(price)
      var data = {};
      if (!price) {
        data = {
          picture: img ? img : 'https://img.bzhz.jnbygroup.com/cloth.png',
          title: title,
          url: '/ec_goods/detail?id=' + id,  // 正式
          // url: '/pages/goods/detail?id=' + id, // 测试
          showCustomMsg: 1
        }
      } else {
        data = {
          picture: img ? img : 'https://img.bzhz.jnbygroup.com/cloth.png',
          title: title,
          price: price,
          url: '/ec_goods/detail?id=' + id,  // 正式
          // url: '/pages/goods/detail?id=' + id, // 测试
          showCustomMsg: 1
        }
      }
      console.log(data)
      window.parent.postMessage(data, '*');
    },
    sendLookCard (img, title, id, num) {
      var data = {
        picture: img ? img : 'https://img.bzhz.jnbygroup.com/cloth.png',
        title: title,
        price: '共' + num + '件商品',
        // url: '/ec_goods/detail?id='+id,  // 正式
        url: '/packages/wm-cloud-jnbyyouda/detail/index?themeId=' + id, // 测试
        showCustomMsg: 1
      }
      console.log(data)
      window.parent.postMessage(data, '*');
    }
  },
}